package org.khd.org.service.impl;

import org.khd.org.domain.Employee;
import org.khd.org.mapper.EmployeeMapper;
import org.khd.org.query.EmployeeQuery;
import org.khd.org.service.IEmployeeService;
import org.khd.base.utils.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class EmployeeServiceImpl implements IEmployeeService {
    @Autowired
    private EmployeeMapper employeeMapper;

    @Override
    @Transactional
    public void insertEmp(Employee employee) {
        employeeMapper.insertEmp(employee);
    }

    @Override
    @Transactional
    public void updateEmp(Employee employee) {
        employeeMapper.updateEmp(employee);
    }

    @Override
    @Transactional
    public void deleteEmpById(Long id) {
        employeeMapper.deleteEmpById(id);
    }

    @Override
    public Employee queryEmpById(Long id) {
        return employeeMapper.queryEmpById(id);
    }

    @Override
    public List<Employee> queryEmpAll() {
        return employeeMapper.queryEmpAll();
    }

    @Override
    public PageList<Employee> queryEmpPage(EmployeeQuery query) {
        //用来查询Employee数据的总条数
        Long total = employeeMapper.queryEmpCount(query);
        //用来查询Employee每页的数据
        List<Employee> list = employeeMapper.queryEmpPage(query);
        return new PageList<>(total, list);
    }

    //批量删除Employee数据
    @Override
    public void patchDeleteEmp(List<Long> ids) {
        employeeMapper.patchDeleteEmp(ids);
    }

    //查询用户名
    @Override
    public Employee getByUsername(String username) {
        return employeeMapper.getByUserName(username);
    }
}
